<script setup>
	import {
		reactive
	} from 'vue';
	import {
		ref,
		getCurrentInstance
	} from 'vue'
	defineProps({
		msg: String
	})
	let api = getCurrentInstance().appContext.config.globalProperties.$api
	let uploadFile = ref(0)
	let chongfu = ref({})
	let showChongfu = ref(false)

	let upload = function() {
		let fordata = new FormData()
		fordata.append("file", uploadFile)
		api.post('http://47.95.170.149:8890/upload', fordata, {
			'Content-type': 'multipart/form-data'
		}).then(e => {
			if (e.data.data) {
				alert(e.data.msg)
				showChongfu = true
				chongfu.value = e.data.data
			}
		})
	}


	let filePreHandle = (event) => {
		const file = event.target.files[0]
		if (file) {
			uploadFile = file
			console.log(file);
		}
	}
</script>

<template>
	<p>选择excel文件</p>
	<input type="file" value="" name="file" @change="filePreHandle">
	<button @click="upload">上传</button>
	<div v-if="chongfu.length">
		<div>重复项:</div>
		<div v-for="(v,k) in chongfu" :key="k">已存在条码::::::{{v.attrs.barCode}}</div>
		<div>重复项以外的数据已添加完成</div>
	</div>


</template>

<style scoped>
	a {
		color: #42b983;
	}
</style>